<?php namespace system\tag;

use houdunwang\view\build\TagBase;

class Common extends TagBase
{
    /**
     * 标签声明
     * @var array
     */
    public $tags = [
        'line' => ['block' => false],
        'category' => ['block' => true, 'level' => 4],
        'slide' => ['block' => true, 'level' => 4],
        'album' => ['block' => true, 'level' => 4],
        'arclist' => ['block' => true, 'level' => 4]
    ];

    public function _line($attr, $content, &$view)
    {
        return 'link';
    }

//    导航条
    public function _category($attr, $content, &$view)
    {
        $pid = isset($attr['pid']) ? $attr['pid'] : -1;
        $str = <<<str
				<?php
					\$db= Db::table('category');
					if($pid>=0){
						\$db->where('cate_pid',$pid);
					}
					\$category_data = \$db->get();
					foreach(\$category_data as \$field):
				?>

					$content
				<?php
					endforeach
				?>
str;
        return $str;
    }

//    轮播图
    public function _slide($attr, $content, &$view)
    {
        $str = <<<str
				<?php
					\$db= Db::table('slide');
					\$slide_data = \$db->get();
					foreach(\$slide_data as \$field):
				?>
					$content
				<?php
					endforeach
				?>
str;
        return $str;
    }

//     文章
    public function _arclist($attr, $content, &$view)
    {
        $cid = isset($attr['cid']) ? $attr['cid'] : -1;
        $thumb = isset($attr['thumb']) ? $attr['thumb'] : -1;
        $row = isset($attr['row']) ? $attr['row'] : -1;
        //图片要求
        $str = <<<str
				<?php
					\$db= Db::table('article');
					if('$cid'>=0){
					    \$db->whereIn('cate_cid',explode(',','$cid'));
					}
					if($thumb==1){
					    \$db->where('arc_thumb','<>','');
					}
					if($row>=0){
						\$article_data = \$db->paginate($row);
					}else{
						\$article_data = \$db->get();
					}
					foreach(\$article_data as \$field):
					    \$field['arc_thumb'] = __ROOT__ . '/' .  \$field['arc_thumb'] ;
					    \$field['url'] = __ROOT__ . '/' .  \$field['arc_id'] . '.html' ;
				?>
					$content
				<?php
					endforeach
				?>
str;

        return $str;
    }

//    相册
    public function _album($attr, $content, &$view)
    {
        $str = <<<str
				<?php
					\$db= Db::table('album');
					\$album_data = \$db->get();
					foreach(\$album_data as \$field):
				?>
					$content
				<?php
					endforeach
				?>
str;
        return $str;
    }
}